package com.ruoyi.labdata.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labdata.domain.LabHoliday;
import com.ruoyi.labdata.service.ILabHolidayService;

/**
 * 工作日Controller
 * 
 * @author winner pan
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/labdata/holiday")
public class LabHolidayController extends BaseController {
	@Autowired
	private ILabHolidayService labHolidayService;

	/**
	 * 查询工作日列表
	 * 公共资源不设权限
	 */
	//@PreAuthorize("@ss.hasPermi('labdata:holiday:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabHoliday labHoliday) {
		startPage();
		List<LabHoliday> list = labHolidayService.selectLabHolidayList(labHoliday);
		return getDataTable(list);
	}

	/**
	 * 导出工作日列表
	 */
	//@PreAuthorize("@ss.hasPermi('labdata:holiday:export')")
	/*@Log(title = "工作日", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(LabHoliday labHoliday) {
		List<LabHoliday> list = labHolidayService.selectLabHolidayList(labHoliday);
		ExcelUtil<LabHoliday> util = new ExcelUtil<LabHoliday>(LabHoliday.class);
		return util.exportExcel(list, "holiday");
	}*/

	/**
	 * 获取工作日详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:holiday:query')")
	@GetMapping(value = "/{dayId}")
	public AjaxResult getInfo(@PathVariable("dayId") Long dayId) {
		return AjaxResult.success(labHolidayService.selectLabHolidayById(dayId));
	}

	/**
	 * 新增工作日
	 */
	@PreAuthorize("@ss.hasPermi('labdata:holiday:edit')")
	@Log(title = "工作日", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabHoliday labHoliday) {
		return toAjax(labHolidayService.insertLabHoliday(labHoliday));
	}

	/**
	 * 修改工作日
	 */
	@PreAuthorize("@ss.hasPermi('labdata:holiday:edit')")
	@Log(title = "工作日", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabHoliday labHoliday) {
		return toAjax(labHolidayService.updateLabHoliday(labHoliday));
	}

	/**
	 * 删除工作日
	 */
	@PreAuthorize("@ss.hasPermi('labdata:holiday:edit')")
	@Log(title = "工作日", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dayIds}")
	public AjaxResult remove(@PathVariable Long[] dayIds) {
		return toAjax(labHolidayService.deleteLabHolidayByIds(dayIds));
	}
}
